home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: recoverPreparedTrans.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:55 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "openlog.h"
- #include "logrecs.h"
- #include "threadstate.h"
- #include "trans_extfuncs.h"
- #include "trans_intfuncs.h"
- #include "recover_intfuncs.h"
- #include "lm_extfuncs.h"
- #include "log_extfuncs.h"
- #include "log_globals.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "trans_globals.h"
- #include "recover_globals.h"
- #include "distr.h"
- #include "distr_globals.h"
-
-
- static
- void
- updateOpenLog(
- register TRANSREC *transRec
- )
- {
- register TRANSREC *currentTrans;
- register OPENLOG *openLog;
-
- TRACE(TR_TRANS|TR_RECOVER, TR_LEVEL_1);
-
- /*
- * update the TransInfo.tidSequence
- */
- if (transRec->tid >= TransInfo.tidSequence ) {
-
- TransInfo.tidSequence = transRec->tid + 1;
- }
-
- /*
- * update ActiveLogSpace
- */
- ActiveLogSpace += transRec->logSpace;
-
- /*
- * get a pointer to the open log
- */
- openLog = &OpenLog;
-
- if (LIST_EMPTY( &(openLog->activeList))) {
-
- /*
- * just move this
- */
- listEnq(&(openLog->activeList), &(transRec->logActiveList));
- }
- else {
- /*
- * get a pointer to the first transaction on the log list
- */
- currentTrans = (TRANSREC *)FIRST_LIST_ELEMENT(&(openLog->activeList));
- while ((currentTrans != NULL) &&
- (compareLSN(&(currentTrans->firstLSN), &(transRec->firstLSN)) <= 0)) {
- currentTrans = (TRANSREC *)NEXT_LIST_ELEMENT(&(currentTrans->logActiveList));
- }
-
- if (currentTrans == NULL) {
- /*
- * put the item last on the list
- */
- listEnq(&(openLog->activeList), &(transRec->logActiveList));
- }
- else {
- /*
- * put it before the current element
- */
- listInsertBefore(&(currentTrans->logActiveList), &(transRec->logActiveList));
- }
- }
- }
-
- void
- recoverPreparedTrans ()
- {
-
- OPENLOG *openLog;
- TRANSREC *transRec; /* current transaction */
- int maxFork; /* max forked undo threads*/
-
- TRACE(TR_TRANS|TR_RECOVER, TR_LEVEL_1);
-
- /*
- * get a pointer to the open log
- */
- openLog = &OpenLog;
-
- /*
- * check if enough threads are available to handle
- * each of the prepared transactions
- */
- maxFork = NumThreads-CONST_THREADS;
-
- if (maxFork < numActiveServerDistrTrans) {
- fprintf(sm_ErrorStream, "SERVER ERROR: insufficient threads to perform undo phase\n");
- SM_ERROR(TYPE_FATAL, esmNOFREETHREAD);
- }
-
- /* proceed down the list */
- transRec = (TRANSREC *) FIRST_LIST_ELEMENT( &ServerDistrTransList );
- while (transRec != NULL) {
-
- /*
- * check the entry magic number
- */
- CHECK_TRANSREC_MAGIC(transRec);
-
- /*
- * update the Openlog activeList
- */
- updateOpenLog(transRec);
-
- /* fork a thread to handle the transaction */
- SM_ASSERT(LEVEL_3, sizeof(FOUR) == sizeof(transRec));
- threadFork(T_PARENT, (PFI) recoverServerPreparedTrans, 1, (FOUR*) &(transRec));
-
- /* get the next transaction */
- transRec = (TRANSREC *) NEXT_LIST_ELEMENT( &(transRec->distrTransList) );
-
- }
-
- /* proceed down the list */
- transRec = (TRANSREC *) FIRST_LIST_ELEMENT( &CoordDistrTransList );
- while (transRec != NULL) {
- /*
- * check the entry magic number
- */
- CHECK_TRANSREC_MAGIC(transRec);
-
- /*
- * update the Openlog activeList
- */
- updateOpenLog(transRec);
-
- /* get the next transaction */
- transRec = (TRANSREC *) NEXT_LIST_ELEMENT( &(transRec->distrTransList) );
- }
-
- /*
- * initialize numPrevActiveCoordDistrTrans
- */
- numPrevActiveCoordDistrTrans = numActiveCoordDistrTrans;
-
- /*
- * set the OpenLog fields
- */
-
- /*
- * get a pointer to the new first transaction record
- */
- if ((transRec = (TRANSREC *)FIRST_LIST_ELEMENT(&(openLog->activeList))) != NULL) {
-
- CHECK_TRANSREC_MAGIC(transRec);
-
- /*
- * update the position information of the new last record
- */
- openLog->activePid = transRec->firstLogPid;
- openLog->activeUnique = transRec->logUnique;
- openLog->activeLSN = transRec->firstLSN.offset;
- TRPRINT(TR_LOG, TR_LEVEL_2, ("new last pid:%d lsn:%d",
- openLog->activePid, openLog->activeLSN));
- }
- }
-